//
//  BwuSetwViewController.m
//  Distributor
//
//  Created by 主事丫环 on 2019/5/15.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "BwuSetwViewController.h"
#import "CSNewChangePhoneViewController.h"
#import "AUserAgreementViewController.h"
#import "IDcardinfofViewController.h"

#import "BBussinessLicenseVC.h"//上传营业执照
#import "BBussinessLicenseAuditVC.h"//营业执照审核
#import "BBussinessLicenseAuditFailVC.h"//营业执照审核失败
#import "BBussinessLicenseShowVC.h"//营业执照审核通过

@interface BwuSetwViewController ()

@end

@implementation BwuSetwViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"设置";
    [self.leftbutton setImage:imgname(@"left_icon") forState:(UIControlStateNormal)];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
    
    [self  requestUserInfoIsInit:YES];
    // Do any additional setup after loading the view from its nib.
}
-(void)requestUserInfoIsInit:(BOOL)isInit{
    kWeakSelf;
    [NetWorkTool POST:CcentenInfo param:nil success:^(id dic) {
        
        self.model = [CSPersonModel mj_objectWithKeyValues:[dic objectForKey:@"data"]];
        if (!isInit) {
            [weakSelf handleUserInfoModel];
        }
        
    } other:^(id dic) {
        ShowToastWithText(dic[@"msg"]);
    } fail:^(NSError *error) {
        
    } needUser:YES];
}
- (void)handleUserInfoModel{
    if ([self.model.licenseState integerValue] == -1) {
        //拒绝
        BBussinessLicenseAuditFailVC *vc = [BBussinessLicenseAuditFailVC new];
        vc.auditFailReason = self.model.licenseRefuseReason;
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.model.licenseState integerValue] == 0){
        //未上传
        [self.navigationController pushViewController:[BBussinessLicenseVC new] animated:YES];
    }else if ([self.model.licenseState integerValue] == 1){
        //审核中
        BBussinessLicenseAuditVC *vc = [BBussinessLicenseAuditVC new];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([self.model.licenseState integerValue] == 2){
        //审核通过
        BBussinessLicenseShowVC *vc = [BBussinessLicenseShowVC new];
        vc.model = self.model;
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark - 修改绑定手机号
- (IBAction)xiugaishoujihao:(UIButton *)sender {//修改绑定手机号
    CSNewChangePhoneViewController *cell = [[CSNewChangePhoneViewController alloc]init];
    [self.navigationController pushViewController:cell animated:YES];
}
#pragma mark - 身份证信息
- (IBAction)shenfenz:(UIButton *)sender {
    //身份证信息
    IDcardinfofViewController *idvc = [[IDcardinfofViewController alloc]init];
    idvc.model = self.model;
    [self.navigationController pushViewController:idvc animated:YES];
}
#pragma mark - 用户协议
- (IBAction)userDelegate:(UIButton *)sender {
    AUserAgreementViewController *userAgree = [[AUserAgreementViewController alloc] init];
    userAgree.model = self.model;
    [self.navigationController pushViewController:userAgree animated:YES];
    
}
#pragma mark - 联系我们
- (IBAction)callUS:(UIButton *)sender {
    [HFTools callMobilePhone:@"400-961-5811"];
}
#pragma mark - 营业执照
- (IBAction)btnBusinessLicenseClickAction:(UIButton *)sender {
    if ([self.model.licenseState integerValue] == 2){
        //审核通过(查看营业执照)
        BBussinessLicenseShowVC *vc = [BBussinessLicenseShowVC new];
        vc.model = self.model;
        [self.navigationController pushViewController:vc animated:YES];
    }else{
        [self requestUserInfoIsInit:NO];
    }
}

#pragma mark - 退出登录
- (IBAction)tuichu:(UIButton *)sender {
    //退出登录
    [NetWorkTool POST:tcagentLoginOut param:nil
              success:^(id dic) {
                  [USER_DEFAULT removeObjectForKey:@"Token"];
                  
                  ShowToastWithText(@"退出成功");
                  //设置Alias
                  [JPUSHService setAlias:nil completion:^(NSInteger iResCode, NSString *iAlias, NSInteger seq) {
                      
                  } seq:0];
                  [self.navigationController popViewControllerAnimated:YES];
              } other:^(id dic) {
                  ShowToastWithText(dic[@"msg"]);
              } fail:^(NSError *error) {
                  
              } needUser:YES];
 
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
